package com.etc.controller;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.etc.entity.Discuss;
import com.etc.entity.Listenworld;
import com.etc.entity.ListenworldExt;
import com.etc.entity.Result;
import com.etc.service.ListenworldService;

/**
 * Listenworld的Controller层
 * @author Administrator
 *
 */
@Controller
@RequestMapping("/world")
public class ListenworldController {
	@Autowired
	private ListenworldService listenworldService;
	/**
	 * 查找Listenworld每一页的数据
	 * @param page
	 * @param catId
	 * @return
	 */
	@RequestMapping("findAllWorld")
	@ResponseBody
	public ListenworldExt findAll(Integer page,Integer catId) {
		return listenworldService.findAllListenworld(page, catId);
	}
	/**
	 * 页面跳转
	 * @return
	 */
	@RequestMapping("pic")
	public String picPage() {
		return "pic";
	}
	/**
	 * 分类查找
	 * @param catId
	 * @param model
	 * @return
	 */
	@RequestMapping("pic_category")
	public String piCategoryPage(Integer catId,Model model) {
		model.addAttribute("qid", catId);
		return "pic";
	}
	/**
	 * 根据id修改点击量
	 * @param lid
	 * @param lcount
	 * @return
	 */
	
	@RequestMapping("updateClick")
	@ResponseBody
	public ListenworldExt updateLcount(Integer lid,Integer lcount) {
		return listenworldService.updateLcount(lid,lcount);
	}
	/**
	 * 详情页
	 * @param lid
	 * @return
	 */
	@RequestMapping("pic_detail")
	public String picDetailPage(Integer lid,@RequestParam(required=true) Integer uid,Model model) {
		int resultCount = listenworldService.updateListenworld(lid);
		if(resultCount > 0) {
			System.out.println("更新成功！");
		}
		//根据lid查找信息并连接查询用户信息
		Result result = listenworldService.findListenWorldAndUser(lid, uid);
		//将信息封装到域对象中
		model.addAttribute("result", result);
		return "pic_detail";
	}
	
	/**
	 * 查询所有图片
	 * @param model
	 * @return
	 */
	@RequestMapping("findAllImgsByPage")
	public String findAllImgsByPage(Integer page,Integer pageSize,Model model) {
		Result result = listenworldService.findAllImgsByPage(page,pageSize);
		model.addAttribute("result", result);
		return "imglist-myimg";
	}
	
	@RequestMapping("updateStatus")
	public String updateStatus(Integer lid,Integer lstatus) {
		listenworldService.updateStatus(lid, lstatus);
		return "forward:findAllImgsByPage";
	}
	
}
